home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / sccs.lqr / sccs.lbr / HDIFF.EXE / HDIFF.DOC < prev    next >
Encoding:
Text File  |  2011-01-31  |  16.5 KB  |  463 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.                                                        26 November, 1984
  9.  
  10.                                   hdiff 1.10
  11.                           Preliminary Documentation
  12.  
  13.        Purpose
  14.        -------
  15.  
  16.        hdiff is a utility which can compare two standard DOS text files
  17.        and isolate the differences between them.  It can produce two
  18.        distinct types of reports on the differences.  First, hdiff can
  19.        prepare a simple report of lines which appear in the second file
  20.        but not in the first (insertions), and of lines which appear in
  21.        the first file but not in the second (deletions).  Second, hdiff
  22.        can produce a special "report" which is, in fact, an Edlin
  23.        script.  This script, when applied to the first file, will
  24.        produce a clone of the second file.  This second function of
  25.        hdiff is quite similar to the Unix utility "diff".
  26.  
  27.        hdiff uses a file comparison algorithm which was developed by
  28.        Paul Heckel and described by D.E.Cortesi in Dr. Dobb's Journal
  29.        #94 (August, 1984).  The algorithm is substantially more
  30.        efficient than traditional file comparison methods; you will find
  31.        that it can generate a difference report between two files in
  32.        little more than the time it takes to read the two files.
  33.  
  34.        This version of hdiff was derived from Cortesi's demonstration
  35.        program, with substantial modifications which
  36.  
  37.        -- accomodate differences between Edlin and CP/M's Ed (for which
  38.        the demo was written)
  39.        -- allow use of Edlin's block move capabilities
  40.        -- allow for much larger files through the use of all available
  41.        memory
  42.        -- allow the use of command line parameters and switches
  43.        -- allow the user to specify at run time the maximum number of
  44.        lines which will be processed.  This allows hdiff to use memory
  45.        more efficiently.
  46.        -- allow the user to request the simpler difference report rather
  47.        than the Edlin script.
  48.  
  49.  
  50.        System requirements
  51.        -------------------
  52.  
  53.        hdiff requires:
  54.  
  55.        -- IBM PC, PC/XT, PC/AT, or other MSDOS machine
  56.        -- MSDOS 2.00 or later
  57.        -- At least 128K of RAM.  The more RAM you have, the larger the
  58.        files you can process.
  59.  
  60.  
  61.        Running hdiff
  62.        -------------
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.        The general syntax for hdiff is:
  73.  
  74.                 hdiff [-e] [-nnnn] oldfile.ext newfile.ext
  75.  
  76.        The optional -e switch instructs hdiff to produce an Edlin script
  77.        file rather than the difference report.  The optional -nnnn
  78.        switch assists in memory management; it represents the maximum
  79.        number of lines hdiff will be required to process, i.e., the
  80.        number of lines in the larger of the two files.  The default for
  81.        this value is 2000 lines; there is an absolute maximum of 5000
  82.        lines.  See the section on memory management for more
  83.        information about this switch.
  84.  
  85.        The two switches may be combined, and they may be in any order:
  86.        '-e -1000', '-1000 -e', '-e1000', and '-1000e' are all
  87.        equivalent.
  88.  
  89.        Examples:
  90.  
  91.                 hdiff foo.c newfoo.c
  92.  
  93.        compares file 'foo.c' with file 'newfoo.c' and produces a simple
  94.        report showing insertions (lines in newfoo which do not appear in
  95.        foo) and deletions (lines in foo which do not appear in newfoo).
  96.        Lines which have been moved but are otherwise unchanged do not
  97.        appear in this report.
  98.  
  99.                 hdiff -e foo.c newfoo.c
  100.  
  101.        compares foo.c with newfoo.c and prepares an Edlin script.  This
  102.        script, if applied to foo, will create a copy of newfoo.  The
  103.        script file is sent to the console, so a more useful command is
  104.  
  105.                 hdiff -e foo.c newfoo.c > foo.dat
  106.  
  107.        which uses standard DOS redirection to send the edlin script to
  108.        the disk file foo.dat.  Note that the program logo and error
  109.        messages are unaffected by redirection and will always be sent to
  110.        the console device.
  111.  
  112.                 hdiff -e4000 foo.c newfoo.c > foo.dat
  113.  
  114.        is equivalent to the previous command, except that it informs
  115.        hdiff that one of the files might contain up to 4000 lines.
  116.  
  117.  
  118.        Report formats
  119.        --------------
  120.  
  121.        The difference report consists of lines in the format:
  122.  
  123.                 [nnnni] text
  124.        or
  125.                 [nnnnd] text
  126.  
  127.        The 'i' format indicates that the line is new (an insertion); the
  128.        'd' format indicates that the line is gone (a deletion).  Thus:
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.                 [   1d] This line appears in the old file only
  139.                 [   1i] This line appears in the new file only
  140.  
  141.        The 'nnnn' represents the line number.  For 'i' lines, it's the
  142.        line number in the new file; for 'd' lines, it's the line number
  143.        in the old file.
  144.  
  145.        The Edlin script is a series of Edlin commands.  See Edlin
  146.        documentation for their meanings; the only commands which will
  147.        appear are I (insert), D (delete), M (move), and E (End).  The
  148.        script may look a little strange if you look at it (with an
  149.        editor or via the TYPE command).  After the completion of each
  150.        insertion sequence, there will be a heart symbol; this is the
  151.        screen representation of Ctrl-C, which is used to terminate an
  152.        Edlin insertion.
  153.  
  154.  
  155.        Uses
  156.        ----
  157.  
  158.        The simplest use for hdiff is to compare two files to see if they
  159.        are the same.  This can be used to check for corruption during
  160.        backups, copies, etc., or to determine which of two files is
  161.        newer.  Even this simple use of hdiff can be useful in unexpected
  162.        ways, however.  For example, look at this small batch file:
  163.  
  164.                 dir a: > temp
  165.                 find "-" temp > dir.a
  166.                 dir b: > temp
  167.                 find "-" temp > dir.b
  168.                 hdiff dir.b dir.a > temp.bat
  169.                 erase dir.a
  170.                 erase dir.b
  171.                 erase temp
  172.  
  173.        This batch can be used for a simple backup system.  Assume that
  174.        the default directory in drive A contains a series of files that
  175.        you want to backup, and that the default directory in drive B
  176.        contains the same set of files from the last backup.  The batch
  177.        will isolate differences between the two directories and prepare
  178.        a file called temp.bat which contains a list of those files which
  179.        have been changed or added since the last backup.  (The .bat
  180.        extension is used because many popular text editors could very
  181.        easily convert the temp.bat file to a series of copy commands
  182.        which could be used, in batch mode, to perform the copying.)
  183.  
  184.        The "Edlin" mode has potentially much more significant use.
  185.        Perhaps its greatest potential lies in what are known as "source
  186.        code control systems".  These systems, quite common in mainframe
  187.        and minicomputer systems, allow programmers to maintain many
  188.        generations of program source text quite economically; rather
  189.        than storing each modified file in its entirety, only the
  190.        original is saved, along with a series of difference files.
  191.  
  192.        Hdiff provides a first step in this direction for MSDOS machines
  193.        (see the "Plans" section below).  Typical use of the current
  194.        hdiff would be something like this.  Assume that hdbase.c
  195.        contains an "original" version of hdiff; the current version
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.        (1.10) is hdiff.c.  First, the command
  205.  
  206.                 hdiff -e hdbase.c hdiff.c > hd110.dat
  207.  
  208.        will create an edlin script which would convert hdbase.c into
  209.        version 1.10 of hdiff.c.  Typically, the actual hdiff.c file
  210.        would them be discarded (WARNING: see below.  This program is
  211.        experimental!)  As newer versions are developed, the same
  212.        procedure is used to create hd111.dat, hd120.dat, etc.  Note that
  213.        these difference files would, in all likelihood, be much smaller
  214.        that the total size of all of the versions.
  215.  
  216.        In order to "retrieve" an eralier version, say 1.00, the command
  217.  
  218.                 copy hdbase.c hdiff.c
  219.                 edlin hdiff.c < hd100.dat
  220.  
  221.        would convert hdbase.c into version 1.00 of hdiff.
  222.  
  223.        True source code control systems are considerably more efficient
  224.        than this "by hand" method, are much easier to use, and provide
  225.        significant features beyond mere storage of multiple versions.
  226.  
  227.        For whatever it's worth, note that
  228.  
  229.                 hdiff -e file1 file2 | edlin file1
  230.  
  231.        is roughly equivalent to
  232.  
  233.                 copy file2 file1
  234.  
  235.        except that the original file1 is saved in file1.bak.
  236.  
  237.  
  238.        cdelta and cget
  239.        ---------------
  240.  
  241.        The two demonstration batches, cdelta and cget, provide a quick
  242.        sample of the kinds of things that can be done with hdiff and
  243.        edlin.  The two batches are designed for C programs; to revise
  244.        them for other languages, simply replace all references to ".c"
  245.        with the desired extension (.asm, for example).
  246.  
  247.        The purpose of cdelta is to generate a change script which will
  248.        convert a "base" source file into a specified version of your
  249.        source.  Cget performs the inverse task; it applies a specified
  250.        change file to the base and produces a file containing the
  251.        specified version.  File naming conventions are as follows:
  252.  
  253.                 file.scc:    "base" source; scc = source code control
  254.                 file.###:    A change script to produce version ###
  255.                 file.c:      The current version (cdelta), or the
  256.                              output file (cget)
  257.  
  258.        For example, suppose you are working with a C program called foo.
  259.        A base (earliest) version of this file should be in foo.scc.  You
  260.        have just finished revision 1.10 of foo.  To create the change
  261.        file, type
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.                 cdelta foo 110
  272.  
  273.        The batch will create a new file, foo.110; this file is an Edlin
  274.        script which will convert foo.scc into version 1.10 of foo.c.
  275.  
  276.        To retrieve a specified version, say 1.05, use
  277.  
  278.                 cget foo 105
  279.  
  280.        The batch will apply the script foo.105 to foo.scc and produce
  281.        foo.c, which will contain the source for version 1.05.
  282.  
  283.        Note that cget always creates a file called file.c, overwriting
  284.        any existing file by that name.  This implies that you do NOT
  285.        keep your current source in file.c; you keep the current source
  286.        only by retaining file.scc and the delta files.
  287.  
  288.        The library contains a set of small files which demonstrate the
  289.        use of cdelta and cget.  The files are: demo.scc (the base file),
  290.        demo.110, demo.120, and demo.125 (difference files for versions
  291.        1.10, 1.20, and 1.25), and demo125.c (the full text of version
  292.        1.25 of the demo program, for comparison purposes).
  293.  
  294.        After you have removed all of the files from the library, I
  295.        suggest that you pass all of the demo files through your text
  296.        editor; the librarian program pads the ends of the files to even
  297.        multiples of bytes, and the demonstration will not work properly.
  298.  
  299.        Try them out; for example, to get version 1.25 of demo, type
  300.  
  301.                 cget demo 125
  302.  
  303.        Compare this file (demo.c) to demo125.c; they should be
  304.        identical.  Make a few changes and save the file, then type
  305.  
  306.                 cdelta demo 130
  307.  
  308.        You now have a change file for your new version.  Erase demo.c
  309.        and try
  310.  
  311.                 cget demo 130
  312.  
  313.        You should have a duplicate of your version 1.30.  (The demo
  314.        "program", by the way, does nothing.  I haven't even compiled it,
  315.        so there may be errors.)
  316.  
  317.  
  318.        Memory management
  319.        -----------------
  320.  
  321.        Hdiff uses all available memory.  The purpose of the -nnnn (max
  322.        number of lines) switch is to allow it to use memory more
  323.        efficiently, and to allow you to more effectively use hdiff in
  324.        very small or very large machines.  This is how it works.
  325.  
  326.        For each *potential* line, hdiff requires approximately 34 bytes
  327.        of storage for various tables.  The default configuration (space
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.        for 2000 lines) will thus require about 68K bytes of data space
  337.        for the tables.  The remainder of available memory (less the size
  338.        of the program itself and a much smaller amount of overhead data)
  339.        is used to store the text read from the files.  Text storage
  340.        space is required for each *unique* line in either file.
  341.  
  342.        If you have a small machine (i.e., less RAM), that much table
  343.        space will leave very little room for text storage; it may even
  344.        be more space than is available, and the program will not run at
  345.        all.  If you find this to be the case, try reducing the number of
  346.        lines via the switch (-1000, or -500, for example.)
  347.  
  348.        Conversely, if you have a very large machine, you will have
  349.        plenty of space available to process file larger than 2000 lines.
  350.        If that is the case, increase the maxlines switch as necessary
  351.        (but remember that in no case can maxlines exceed 5000).
  352.  
  353.        When hdiff is finished, it displays a message like:
  354.  
  355.                 Storage use: 19%
  356.  
  357.        This message tells you approximately what percentage of the total
  358.        available memory was actually used.
  359.  
  360.  
  361.        Restrictions
  362.        ------------
  363.  
  364.        The following act, in one way or another, as restrictions on
  365.        hdiff:
  366.  
  367.        -- File format.  Hdiff is intended as a DOS text file comparator
  368.        only.  It is not a replacement for the DOS utility 'comp'.  Don't
  369.        use it on binary (program or data) files, or on word processor
  370.        files if they contain embedded control codes.
  371.        -- Available memory (as discussed above)
  372.        -- Actual size of the files. Edlin will read a file only until
  373.        75% of its available memory is filled.  Since Edlin uses only a
  374.        maximum of 64K, this means that it will read only 48K of text.
  375.        Hdiff cannot account for this problem, so the absolute maximum
  376.        file size it can handle is approximately 48K.
  377.        -- Line size.  Limited to a maximum of 255 characters/line.
  378.        -- Use of tabs.  If your text editor gives you a choice in saving
  379.        text with or without tabs, try to be consistent.  That is, try
  380.        to avoid using hdiff on one file saved with tabs, and one file
  381.        saved without.
  382.  
  383.  
  384.        A Warning and A Plan
  385.        --------------------
  386.  
  387.        Hdiff is experimental!  It has been tested, but there have not
  388.        been sufficient tests to state with any great degree of
  389.        confidence that it will perform "as advertised" with all possible
  390.        files.  Please bear this in mind as you use it.  Please report
  391.        any problems to me.
  392.  
  393.        I intend, at some "unspecified future time", to incorporate hdiff
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.        or a version of it in a larger source code control system.  This
  403.        system would allow you to maintain multiple generations of
  404.        program source files very efficiently (in terms of storage
  405.        requirements).  Some knotty problems relating to performance on a
  406.        standard-issue PC remain to be solved.  Comments or suggestions
  407.        relating to this system are welcome.  Tell me what you would like
  408.        to see.
  409.  
  410.  
  411.                             ---------------------
  412.  
  413.                          hdiff and this document are
  414.                             Copywrite (c) 1984 by:
  415.  
  416.                             Christopher J. Dunford
  417.                            10057-2 Windstream Drive
  418.                            Columbia, Maryland 21044
  419.                             CompuServe 71076,1115
  420.                                 Source STR211
  421.  
  422.        You may copy and use hdiff for your personal use only.  You may
  423.        copy hdiff for others, but you may not charge them for it.  You
  424.        may not use hdiff for any commercial purpose whatsoever.  Address
  425.        comments to the author at the above address, at CompuServe
  426.        (preferably) or at the Source (occasionally).
  427.  
  428.        Hdiff is written in C and compiled using the Computer Innovations
  429.        C86 compiler (Version 2.13), big model.
  430.  
  431.  
  432.  
  433.  
  434.  
  435.  
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.